
// pages/demo/demo.js
Page({
  data:{
    isHidden:false,
  },
  onShow(){
    let userInfo=wx.getStorageSync('userInfo')
    if(userInfo && userInfo.nickName){
      this.setData({
        userInfo:userInfo
      })
    }
  },
  //获取用户头像
  getAvatar(e){
    this.setData({
      avatarUrl:e.detail.avatarUrl
    })
  },
  getName(e){
    this.setData({
      nickName:e.detail.value
    })
  },
  login(){
    let avatarUrl=this.data.avatarUrl
    let nickName=this.data.nickName
    if(!avatarUrl){
      wx.showToast({
        icon:'error',
        title:'请获取头像',
      })
      return
    }
    if(!nickName){
      wx.showToast({
        icon:'error',
        title:'请获取昵称',
      })
      return
    }
    // 数据缓存
    let userInfo={}
    userInfo.avatarUrl=avatarUrl
    userInfo.nickName=nickName
    wx.setStorageSync('userInfo', userInfo)
    this.setData({
      isHidden:true,
      userInfo:userInfo
    })
    wx.switchTab({
       url: '/pages/home/home'
     });
  }
})
